﻿using Yitter.IdGenerator;

namespace Common.Class
{
    public class CommonHelper
    {
        public static IdGeneratorOptions options;

        public static long GetNewID(int workerId = 1, DateTime? beginTime = null)
        {
            _ = DateTime.Now;
            if (!beginTime.HasValue)
            {
                beginTime = Convert.ToDateTime("2000-01-01");
            }

            if (options == null)
            {
                options = new IdGeneratorOptions
                {
                    Method = 1,
                    WorkerId = (ushort)workerId,
                    WorkerIdBitLength = 6,
                    SeqBitLength = 6,
                    BaseTime = beginTime.Value
                };
                YitIdHelper.SetIdGenerator(options);
            }

            return YitIdHelper.NextId();
        }

    }
}
